package org.example;

import com.sun.corba.se.spi.orbutil.threadpool.ThreadPool;
import com.sun.corba.se.spi.orbutil.threadpool.WorkQueue;

import java.util.concurrent.*;

public class Test2 {

    private volatile static int temp;

    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {

        long start=System.currentTimeMillis();

        ThreadLocal<Integer> threadLocal = new ThreadLocal<>();

        // 在这里创建一个线程或线程池，
        Runnable task = new Runnable() {
            @Override
            public void run() {
                temp = sum();
            }
        };

        Thread thread = new Thread(task);
        thread.start();

        Thread.sleep(500);

        //这是得到的返回值
        int result = temp;

        // 确保  拿到result 并输出
        System.out.println("异步计算结果为："+result);

        System.out.println("使用时间："+ (System.currentTimeMillis()-start) + " ms");

        // 然后退出main线程
    }

    private static int sum() {
        return fibo(36);
    }

    private static int fibo(int a) {
        if ( a < 2){
            return 1;
        }

        return fibo(a-1) + fibo(a-2);
    }
}
